home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / feb93.zip / LA_INT.LSP < prev    next >
Lisp/Scheme  |  1993-02-12  |  2KB  |  54 lines

  1. ; LA_INT.LSP
  2. ; Purpose: Loaded by XINT.LSP to find intersection 
  3. ; of a line with an arc/circle. Variables are defined 
  4. ; in XINT.LSP
  5. ; Version: 1.1
  6. ; Author: Glenn S. Lyford  5/20/90
  7. ; Revised: George E. Zinsmeister  10/20/90
  8. ;================================================
  9. ;
  10. (setq
  11.   PL1 (cdr (assoc 10 EL1))      ;start of line
  12.   PL2 (cdr (assoc 11 EL1))      ;end of line
  13.   C2 (cdr (assoc 10 EL2))       ;center of arc/circle
  14.   R2 (cdr (assoc 40 EL2))       ;radius of arc/circle
  15.   AL (angle PL1 PL2)            ;absolute angle of line
  16.   A1 (angle PL1 C2)             ;absolute angle from first
  17.                                 ;line point to center
  18.   A2 (abs (- A1 AL))            ;relative angle between 
  19.                                 ;line and pt-ctr line
  20.   DC (distance PL1 C2)          ;distance from first point
  21.                                 ;to center
  22.   D (* DC (sin A2))             ;distance of center from 
  23.                                 ;closest point of line
  24.   PP (polar PL1 AL (* DC (cos A2)))  ;closest point of line
  25. )
  26. (cond
  27.   ((< D R2)
  28.     (progn                       ;otherwise calculate point
  29.                                  ;of intersection
  30.       (setq
  31.         DP (sqrt (- (* R2 R2) (* D D))) ;distance of 
  32.                                    ;desired point from PP
  33.         P1 (polar PP AL DP)        ; point on one side of PP
  34.         P2 (polar PP (+ AL pi) DP) ;point on other side 
  35.                                    ;of PP
  36.       )
  37.       (if (<= (distance P1 PS1) (distance P2 PS1)) 
  38.                                   ;set PNEAR and PFAR
  39.         (setq PNEAR P1 PFAR P2)
  40.         (setq PFAR P1 PNEAR P2)
  41.       )
  42.       (if (= NF 0) (setq P PNEAR) (setq P PFAR))
  43.                                   ;choose PNEAR or PFAR
  44.     ) ;end progn
  45.   )
  46.   ((equal D R2 (* 0.0001 (getvar "dimscale"))) (setq P PP))
  47.                                  ;tangent point
  48. ; note that "fuzz" to determine tangency is related 
  49. ; to "dimscale" - this
  50. ; criterion can be changed according to specific application
  51.   (T (setq P nil))            ;no intersection so return nil
  52. );end la_int.lsp
  53.  
  54.